home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0005_FUNCPARA.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  689b  |  38 lines

  1. This is legal syntax For Turbo/Borland Pascal v.6 and above:
  2.  
  3. Type
  4.   MathFunc = Function (x:Real):Real;
  5.  
  6.   Function MyFunc(x:Real):Real;
  7.   begin
  8.     MyFunc:=2 * Sin(x) + Cos(x);
  9.   end;
  10.  
  11.   Function YetAnother(x:Real):Real;
  12.   begin
  13.     YetAnother:=Sqr(x) + x/2 + 1;
  14.   end;
  15.  
  16.   Function AreaUnder(f:MathFunc; Lo, Hi:Real; Steps:Integer):Real;
  17.   Var
  18.     sum,
  19.     x,
  20.     dx  : Real;
  21.     i   : Integer;
  22.   begin
  23.     dx:=(Hi-Lo)/Steps;
  24.     sum:=0;
  25.     x:=Lo;
  26.     For i:=1 to Steps
  27.     do begin
  28.       sum:=sum + f(x);
  29.       x:=x + dx;
  30.     end;
  31.   end;
  32.  
  33.   begin
  34.     Writeln(AreaUnder(MyFunc, 0, 2*PI, 360));
  35.     Writeln(AreaUnder(YetAnother, -1,1, 100));
  36.   end.
  37.  
  38.